package com.bh.web.controller.vehicle;

import com.bh.common.annotation.Log;
import com.bh.common.core.controller.BaseController;
import com.bh.common.core.domain.AjaxResult;
import com.bh.common.core.page.TableDataInfo;
import com.bh.common.enums.BusinessType;
import com.bh.common.utils.poi.ExcelUtil;
import com.bh.vehicle.domain.JcVehicle;
import com.bh.vehicle.service.IJcVehicleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 车型管理Controller
 * 
 * @author slx
 * @date 2023-11-26
 */
@RestController
@RequestMapping("/vehicle/vehicle")
public class JcVehicleController extends BaseController
{
    @Autowired
    private IJcVehicleService jcVehicleService;

    /**
     * 查询车型管理列表
     */
    @ApiOperation("查询车型管理列表")
    @PreAuthorize("@ss.hasPermi('vehicle:vehicle:list')")
    @GetMapping("/list")
    public TableDataInfo list(JcVehicle jcVehicle)
    {
        startPage();
        List<JcVehicle> list = jcVehicleService.selectJcVehicleList(jcVehicle);
        return getDataTable(list);
    }

    /**
     * 查询车型管理列表
     */
    @ApiOperation("查询车型管理列表")
    @GetMapping("/allList")
    public AjaxResult allList(JcVehicle jcVehicle)
    {
        List<JcVehicle> list = jcVehicleService.selectJcVehicleList(jcVehicle);
        return AjaxResult.success(list);
    }


    /**
     * 导出车型管理列表
     */
    @PreAuthorize("@ss.hasPermi('vehicle:vehicle:export')")
    @Log(title = "车型管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, JcVehicle jcVehicle)
    {
        List<JcVehicle> list = jcVehicleService.selectJcVehicleList(jcVehicle);
        ExcelUtil<JcVehicle> util = new ExcelUtil<JcVehicle>(JcVehicle.class);
        util.exportExcel(response, list, "车型管理数据");
    }

    /**
     * 获取车型管理详细信息
     */
    @ApiOperation("获取车型管理详细信息")
    @PreAuthorize("@ss.hasPermi('vehicle:vehicle:query')")
    @GetMapping("/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(jcVehicleService.selectJcVehicleById(id));
    }

    /**
     * 新增车型管理
     */
    @ApiOperation("新增车型管理")
    @PreAuthorize("@ss.hasPermi('vehicle:vehicle:add')")
    @Log(title = "车型管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody JcVehicle jcVehicle)
    {
        return toAjax(jcVehicleService.insertJcVehicle(jcVehicle));
    }

    /**
     * 修改车型管理
     */
    @ApiOperation("修改车型管理")
    @PreAuthorize("@ss.hasPermi('vehicle:vehicle:edit')")
    @Log(title = "车型管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody JcVehicle jcVehicle)
    {
        return toAjax(jcVehicleService.updateJcVehicle(jcVehicle));
    }

    /**
     * 删除车型管理
     */
    @ApiOperation("删除车型管理")
    @PreAuthorize("@ss.hasPermi('vehicle:vehicle:remove')")
    @Log(title = "车型管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(jcVehicleService.deleteJcVehicleByIds(ids));
    }
}
